<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes">
<title>商城购物车</title>
<link rel="stylesheet" type="text/css" href="/static/css/style.css">
<link rel="stylesheet" type="text/css" href="/static/css/shoujisc.css">
<script type="text/javascript" src="/static/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="/static/js/woxiangyao.js"></script>
<script type="text/javascript" src="/static/js/TouchSlide.1.1.js"></script>
<script type="text/javascript" src="/static/js/foot.js"></script>
<script type="text/javascript" src="/static/js/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript" src="/static/js/myinit.js"></script>

<script type="text/javascript" src="/static/js/xujianbanner.js"></script>

<style type="text/css">
	.addOne{
	
		
	}
	.addOne img{ 
		
	
	}
	.minus{
	
		
	}
	.minus img{ 
	
	}
	.numshow{
		 
		 
	}
	.mygroup{
		border:1px solid #dcdcdc;
		display:inline-block;
		height:30px;
	}
	
	.mygroupitem{
		display:inline-block;
		
		background-position:center;
		background-repeat:no-repeat;
		background-size:20px 20px;
		height:30px;
		min-width:30px;
	
	}
</style>
<script type="text/javascript" src="/static/js/cook_shop_cart.js"></script>	


</head>

<body>

 <div class="sjsc-title2" style="height:44px">
    	<h3 class="sjsc-t2l" style="height:44px;line-height:44px">购物车</h3>
        <a href="javascript:history.back();" class="sjsc-t2r" style="height:44px;line-height:44px;background-image:url('/static/img/back.png');width:44px;background-position:center;background-repeat:no-repeat;background-size:30px;30px;"> </a>
        
    </div>
	
	
	 
    
    <ul class="gwc-ul1">
    	
       
    </ul>
    
    <div class="gwc-ft" style="height:40px;padding-top:5px;padding-bottom:5px;">
    	<button id="cmf" style="margin-right:12px;height:40px;width:auto;width:80px;font-size:16px;float:right">去支付</button>
    	<p style="height:40px;line-height:40px;font-size:14px;float:left">共<span id="total_all">0</span>件商品，总计:<span>￥<span id="price_all">0.00</span><span></p>
        
        <div style="clear:both;"></div>
    </div>
	
	<script type="text/javascript">
		var openid =getUrldata('OPENID');
	
		$(document).ready(function(){
			pageinitcart();
			
		});
		function pageinitcart(){
			var cartt=cartHelper.getCart();
			var items=cartt.items;
			$.each(items,function(index,item){
				initGood(item.id,item.goodid,item.count,item.img,item.xiangqing);
			
			});
			refreshAll();
		}
		
		function initGood(id,goodid,count,img,xiangqing){
			var url="/webserver/api/v1/good/?format=json&id="+goodid;
			 
			$.getJSON(url,function(rs){
			 
				var item=rs.objects[0];
				var minus_img="/static/img/jianhao.png";
				if(count>1){
					minus_img="/static/img/jianhao_black.png";
				}
				$('ul').append('<li id="'+id+'" style="position:relative"><div class="hwc-tu f-l"><a href="#"><img src="'+img+'"></a></div><div class="gwc-md f-l" style="width:60%"><h3><a href="#" style="font-size:14px">'+item.name+'</a></h3><p class="gwc-p1" style="font-size:14px">售价：<span>￥'+item.price+'</span>剩余：<span>'+item.stock+'</span>台</p><p class="gwc-p2" style="font-size:12px">'+xiangqing+'</p></div><a href="#" class="gwc-del f-r"><img src="/static/img/sjsc-10.gif"></a><div style="vertical-align: middle;position: absolute;left: 100px;bottom: 6px;" class="mygroup"><div class="mygroupitem minus" style="background-image: url(&quot;'+minus_img+'&quot;); width: 30px; height: 30px;border-right:1px solid #dcdcdc;" id="minusOne"></div><div class="mygroupitem" style="  height: 30px;"><input style="float: left; line-height: 30px; height: 30px; border: medium none; text-align: center; background-color: transparent; width: 60px;" class="numshow" value="'+count+'" type="tel"></div><div class="mygroupitem addOne" id="addOne" style="background-image: url(&quot;/static/img/jiahao.png&quot;); width: 30px; height: 30px;border-left:1px solid #dcdcdc;"></div></div><div style="clear:both;"></div></li>');
				/**
				<a href="#" class="gwc-del f-r"><img src="/static/img/sjsc-10.gif"></a> <a href="#" class="f-r minus" ><img src="/static/img/jianhao.png"></a><a href="#" class="f-r "  >'+count+'</a><a href="#" class="f-r addOne" ><img src="/static/img/jiahao.png"></a>
				*/
				 
				$('ul li#'+id).find('.gwc-del').click(function(){
					cartHelper.Del(id) ;
					$('ul li#'+id).remove();
					refreshAll();
					
					 
				});
				
				$('ul li#'+id).find('.addOne').click(function(){
					 
					cartHelper.addOne(id) ;
					$('ul li#'+id).find('.numshow').val(cartHelper.Finditem(id).count);
					refreshAll();
					$('ul li#'+id).find('.minus').css('background-image','url("/static/img/jianhao_black.png")');
					 
				});
				
				$('ul li#'+id).find('.minus').click(function(){
					 
					cartHelper.DelOne(id) ;
					var aa=cartHelper.Finditem(id);
					if(aa==null){
						$('ul li#'+id).remove();
					}else{
						$('ul li#'+id).find('.numshow').val(cartHelper.Finditem(id).count);
						if(aa.count<2){
							$('ul li#'+id).find('.minus').css('background-image','url("/static/img/jianhao.png")');
						}
					}
					refreshAll();
					
					
					 
				});
				
				$('ul li#'+id).find('.numshow').change(function(e) {
					var cart = cartHelper.getCart();
					var index = cartHelper.Find(id);
					if (index > -1) {
						
					} else {
						alert('非法页面');	
					}
					
					var now_num=parseInt($(this).val());
					var count=0;
					if(now_num>0){
						count=now_num-cart.items[index].count;
						
					}else{
						return;
					}
					
					cart.items[index].count+=count;
					cart.count+=count;
					cart.total += parseInt(cart.items[index].price*count);
					cartHelper.Save();
					$('ul li#'+id).find('.numshow').val(cartHelper.Finditem(id).count);
					if(cart.items[index].count<2){
						$('ul li#'+id).find('.minus').css('background-image','url("/static/img/jianhao.png")');
					}
					 
					refreshAll();
					
                });
				
			
			
             
			
			});
		}
		
		function refreshAll(){
			var carrt=cartHelper.getCart();
			$('#total_all').html(carrt.count);
			$('#price_all').html((carrt.total*0.01).toFixed(2));
			
		}
		$('#cmf').click(function(){
			var carrt=cartHelper.getCart();
			if(carrt.count!=0){
				window.location.href='queren_nodizhi.html?OPENID='+openid;
			}else{
				toast('购物车里没有东西!');
			}
			
		});
		
		
		
		
		
	
	</script>
</body>
</html>
